package com.example.shixi.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.shixi.mapper.BookMapper;
import com.example.shixi.pojo.Book;
import com.example.shixi.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookServiceImpl2 implements BookService {

    @Autowired
    private BookMapper mapper;


    @Override
    public Book getById(Integer id) {
        return mapper.selectById(id);
    }

    @Override
    public List<Book> getAll() {
        return mapper.selectList(null);
    }

    @Override
    public boolean save(Book book) {
        return mapper.insert(book)>0;
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id)>0;
    }

    @Override
    public boolean update(Book book) {
        return mapper.updateById(book)>0;
    }

    @Override
    public IPage<Book> getByPage(Integer current, Integer size) {
        IPage<Book> iPage = new Page<Book>(current, size);
        return mapper.selectPage(iPage,null);
    }
}

